//
//  Huati_taolun_fabu_vc.m
//  ainkjj
//
//  Created by MAX on 2020/4/29.
//  Copyright © 2020 zhiyiLiu. All rights reserved.
//

#import "Huati_taolun_fabu_vc.h"
#import "LxGridViewFlowLayout.h"
#import "TZTestCell.h"
#import <Photos/Photos.h>
#import <ZLPhotoBrowser/ZLPhotoBrowser.h>
#import "PPNetworkHelper.h"



@interface Huati_taolun_fabu_vc ()
<QMUITextFieldDelegate, QMUITextViewDelegate, UICollectionViewDataSource, UICollectionViewDelegate>

@property(nonatomic, strong) QMUITextField *biaoti_tf;
@property(nonatomic, strong) UILabel *shangchuan_tupian_tips_lb;
@property(nonatomic, strong) CALayer *separatorLayer1;


@property(nonatomic,strong) QMUITextView *textView;
@property(nonatomic, assign) CGFloat textViewMinimumHeight;
@property (nonatomic, assign)CGFloat textViewMaximumHeight;
@property (nonatomic, assign)NSUInteger maximumPhotos;
@property (nonatomic, strong) UICollectionView *collectionView;
@property (strong, nonatomic) LxGridViewFlowLayout *layout;


@property (nonatomic, strong) NSMutableArray<UIImage *> *lastSelectPhotos;
@property (nonatomic, strong) NSMutableArray<PHAsset *> *lastSelectAssets;

@property (nonatomic, strong) NSArray *arrDataSources;

@property (nonatomic, assign) BOOL isOriginal;
@property(nonatomic, strong) UIButton *normalButton;
@property (nonatomic, strong)NSMutableArray *file_url_muArr;


@end

@implementation Huati_taolun_fabu_vc{
    
    CGFloat _itemWH;
    CGFloat _margin;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
}

- (void)didInitialize{
    [super didInitialize];
    self.automaticallyAdjustsScrollViewInsets = NO;
    self.textViewMinimumHeight = 140;
    self.textViewMaximumHeight = ScreenHeight - 310 - Lzy_StatusBarAndNavigationBarHeight - Lzy_TabbarSafeBottomMargin;
    self.maximumPhotos = 3;
}
- (void)initSubviews {
    [super initSubviews];
    
    _biaoti_tf = [[QMUITextField alloc] init];
    self.biaoti_tf.delegate = self;
    //    self.textField.maximumTextLength = 10;
    self.biaoti_tf.placeholder = @"在这里填写标题";
    self.biaoti_tf.font = UIFontMake(16);
    //    self.textField.layer.cornerRadius = 2;
    //    self.textField.layer.borderColor = UIColorSeparator.CGColor;
    //    self.textField.layer.borderWidth = PixelOne;
    //    self.biaoti_tf.textInsets = UIEdgeInsetsMake(0, 16, 0, 16);
    self.biaoti_tf.clearButtonMode = UITextFieldViewModeAlways;
    [self.view addSubview:self.biaoti_tf];
    
    
    self.separatorLayer1 = [QDCommonUI generateSeparatorLayer];
    [self.view.layer addSublayer:self.separatorLayer1];
    
    
    self.textView = [[QMUITextView alloc] init];
    self.textView.delegate = self;
    self.textView.placeholder = @"在这里表达自己的态度";
    self.textView.placeholderColor = UIColorPlaceholder; // 自定义 placeholder 的颜色
    //    self.textView.textContainerInset = UIEdgeInsetsMake(10, 7, 10, 7);
    self.textView.returnKeyType = UIReturnKeySend;
    self.textView.enablesReturnKeyAutomatically = YES;
    self.textView.typingAttributes = @{NSFontAttributeName: UIFontMake(15),
                                       NSParagraphStyleAttributeName: [NSMutableParagraphStyle qmui_paragraphStyleWithLineHeight:20],
                                       NSForegroundColorAttributeName: self.textView.textColor
    };
    self.textView.backgroundColor = UIColor.qd_backgroundColorLighten;
    // 限制可输入的字符长度
    self.textView.maximumTextLength = 1000;
    
    // 限制输入框自增高的最大高度
    self.textView.maximumHeight = self.textViewMaximumHeight;
    //
    //    self.textView.layer.borderWidth = PixelOne;
    //    self.textView.layer.borderColor = UIColorSeparator.CGColor;
    //    self.textView.layer.cornerRadius = 4;
    [self.view addSubview:self.textView];
    
    
    // 如不需要长按排序效果，将LxGridViewFlowLayout类改成UICollectionViewFlowLayout即可
    _layout = [[LxGridViewFlowLayout alloc] init];
    _collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:_layout];
    //    CGFloat rgb = 244 / 255.0;[UIColor colorWithRed:rgb green:rgb blue:rgb alpha:1.0];
    _collectionView.alwaysBounceVertical = YES;
    _collectionView.backgroundColor = UIColor.whiteColor;
    _collectionView.contentInset = UIEdgeInsetsMake(4, 4, 4, 4);
    _collectionView.dataSource = self;
    _collectionView.delegate = self;
    _collectionView.keyboardDismissMode = UIScrollViewKeyboardDismissModeOnDrag;
    [self.view addSubview:_collectionView];
    [_collectionView registerClass:[TZTestCell class] forCellWithReuseIdentifier:@"TZTestCell"];
    
    CGFloat margin = 16;
    _margin = margin;
    
    CGFloat itemWH = (ScreenWidth - margin * 2 - margin * 2)/ self.maximumPhotos ;
    _itemWH = itemWH;
    _layout.itemSize = CGSizeMake(_itemWH, _itemWH);
    _layout.minimumInteritemSpacing = 2;
    _layout.minimumLineSpacing = 2;
    [self.collectionView setCollectionViewLayout:_layout];
    //    CGFloat collectionViewY = CGRectGetMaxY(textView.frame);
    //    self.collectionView.frame = CGRectMake(0, collectionViewY, self.view.tz_width, self.view.tz_height - collectionViewY);
    
    
    
    self.shangchuan_tupian_tips_lb = [[UILabel alloc] init];
    self.shangchuan_tupian_tips_lb.text = [NSString stringWithFormat:@"最多上传%lu张照片",(unsigned long)self.maximumPhotos];
    self.shangchuan_tupian_tips_lb.font = UIFontMake(12);
    self.shangchuan_tupian_tips_lb.textColor = UIColor.qd_descriptionTextColor;
    [self.view addSubview:self.shangchuan_tupian_tips_lb];
    
    // 普通按钮
    UIButton *button = [[UIButton alloc] init];
    self.normalButton = button;
    button.titleLabel.font = UIFontBoldMake(14);
    [button setTitleColor:UIColorWhite forState:UIControlStateNormal];
    //            button.backgroundColor = UIColor.qd_tintColor;
    [self.normalButton setTitle:@"发布" forState:UIControlStateNormal];
    [self.view addSubview:self.normalButton];
    self.normalButton.layer.cornerRadius = 44 * 0.5;
    self.normalButton.layer.masksToBounds = YES;
    [button addTarget:self action:@selector(fabu_action:) forControlEvents:UIControlEventTouchUpInside];
}

- (void)viewDidLayoutSubviews {
    [super viewDidLayoutSubviews];
    UIEdgeInsets padding = UIEdgeInsetsMake(Lzy_StatusBarAndNavigationBarHeight + 16, 16 + self.view.qmui_safeAreaInsets.left, 16 + self.view.qmui_safeAreaInsets.bottom, 16 + self.view.qmui_safeAreaInsets.right);
    CGFloat contentWidth = CGRectGetWidth(self.view.bounds) - UIEdgeInsetsGetHorizontalValue(padding);
    self.biaoti_tf.frame = CGRectMake(padding.left, padding.top, contentWidth, 40);
    
    self.separatorLayer1.frame = CGRectMake(0, CGRectGetMaxY(self.biaoti_tf.frame) + PixelOne, CGRectGetWidth(self.view.bounds), PixelOne);
    
    CGSize textViewSize = [self.textView sizeThatFits:CGSizeMake(contentWidth, CGFLOAT_MAX)];
    self.textView.frame = CGRectMake(padding.left, CGRectGetMaxY(self.biaoti_tf.frame) + PixelOne + 10, CGRectGetWidth(self.view.bounds) - UIEdgeInsetsGetHorizontalValue(padding), fmax(textViewSize.height, self.textViewMaximumHeight));
    
    [self.collectionView setFrame:CGRectMake(padding.left, self.textViewMaximumHeight + CGRectGetMinY(self.textView.frame), ScreenWidth - padding.left * 2, _itemWH + 10)];
    
    
    self.shangchuan_tupian_tips_lb.frame = CGRectFlatMake(padding.left, CGRectGetMaxY(self.collectionView.frame) + 8, contentWidth, QMUIViewSelfSizingHeight);
    
    
    // 普通按钮
    
    
    CGFloat btnWidth = ScreenWidth - 30 * 2;
    self.normalButton.frame = CGRectMake((self.view.bounds.size.width - btnWidth) * 0.5, CGRectGetMaxY(self.shangchuan_tupian_tips_lb.frame) + 30, btnWidth, 44);
    [self.normalButton setBackgroundImage:[Anktool gradient_img_create:rgb(255,107,149) toColor:rgb(255,163,191) frame:self.normalButton.frame] forState:UIControlStateNormal];
    
    
    
}
- (void)uploadImgIndex:(NSInteger)index qmui_tip:(QMUITips *)qmui_tip{
    // 开始网络请求任务
    
    
    NSArray *arr = @[self.lastSelectPhotos[index]];
    NSString *img_name = [AuthSignin_model.sharedInstance.data.user_info.mobile stringByAppendingString:@(NSDate.date.timeIntervalSince1970).stringValue]
    ;
    NSString *url_str = @"api/Upload/image";
    NSDictionary *params = @{@"Authorization" : AuthSignin_model.sharedInstance.data.token};
    
    
    [PPNetworkHelper uploadImagesWithURL:url_str parameters:params name:@"file" images:arr fileNames:@[img_name] imageScale:0.3 imageType:nil progress:^(NSProgress *progress) {
        
    } success:^(id responseObject) {
        DLog(@"url:%@ params:%@ res:%@", url_str, params, responseObject);
        NSDictionary *response = responseObject;
        NSString *error_code = [NSString stringWithFormat:@"%@", response[@"error_code"]];
        if ([error_code isEqualToString:@"0"]) {
            
            NSDictionary *data_dic = response[@"data"];
            NSString *uploaded_url = [NSString stringWithFormat:@"%@", [data_dic objectForKey:@"url"]];
            if (uploaded_url.length > 0 ) {
                [self.file_url_muArr addObject:uploaded_url];
                
                if (self.file_url_muArr.count == self.lastSelectPhotos.count) {
                    
                    [qmui_tip showLoading:@"上传成功，发布中..."];
                    
                    NSMutableDictionary *dict = [NSMutableDictionary dictionary];
                    [dict setObject:app_code forKey:@"appCode"];
                    [dict setObject:AuthSignin_model.sharedInstance.data.token forKey:@"token"];
                    
                    [dict setObject:@"1" forKey:@"topicType"];
                    [dict setObject:self.biaoti_tf.text forKey:@"titel"];
                    [dict setObject:self.textView.text forKey:@"content"];
                    [dict setObject:[self.file_url_muArr componentsJoinedByString:@","] forKey:@"files"];
                    
                    [PPHTTPRequest req:@"java/app/topic/pubTopic" parameters:dict success:^(id response) {
                        NSString *error_code = [NSString stringWithFormat:@"%@", response[@"error_code"]];
                        if ([error_code isEqualToString:@"0"]) {
                            
                            [qmui_tip showSucceed:@"发布成功" hideAfterDelay:2];
                            
                            [self finishFabu];
                            
                        }
                        else{
                            
                            
                            [qmui_tip showError:response[@"error_msg"] hideAfterDelay:2];
                            
                        }
                        
                        
                    } failure:^(NSError *error) {
                        [qmui_tip showError:[error localizedDescription] hideAfterDelay:2];
                        
                    }];
                    
                    
                    
                }else{
                    [self uploadImgIndex:index+1 qmui_tip:qmui_tip];
                }
            }
            
        }
        
        else
            //            if ([error_code isEqualToString:@""])
        {
            
            [qmui_tip showError:response[@"error_msg"] hideAfterDelay:2];
            
        }
        
        
        
    } failure:^(NSError *error) {
        [qmui_tip showError:error.localizedDescription hideAfterDelay:2];
        
        
        
    }];
    
    
    
}
- (void)finishFabu{
    [[NSNotificationCenter defaultCenter] postNotificationName:@"话题java/app/topic/pubTopic" object:nil];

    [self.navigationController popViewControllerAnimated:YES];
}
- (void)fabu_action:(UIButton *)sender{
    
    
    if (self.biaoti_tf.text.length == 0) {
        [QMUITips showInfo:@"请输入标题"];
        return;
    }
    if (self.textView.text.length == 0) {
        [QMUITips showInfo:@"请输入内容"];
        return;
    }
    
    // 如果有文件，先上传文件
    if (self.lastSelectPhotos.count > 0) {
        
        self.file_url_muArr = [NSMutableArray array];
        QMUITips *qmui_tip = [QMUITips showLoading:@"图片上传..." inView:self.navigationController.view];
        [self uploadImgIndex:0 qmui_tip:qmui_tip];
        
    }else{
        NSMutableDictionary *dict = [NSMutableDictionary dictionary];
        [dict setObject:app_code forKey:@"appCode"];
        [dict setObject:AuthSignin_model.sharedInstance.data.token forKey:@"token"];
        
        [dict setObject:@"1" forKey:@"topicType"];
        [dict setObject:self.biaoti_tf.text forKey:@"titel"];
        [dict setObject:self.textView.text forKey:@"content"];
        //sender.userInteractionEnabled = NO;
        
        [PPHTTPRequest req:@"java/app/topic/pubTopic" parameters:dict success:^(id response) {
            NSString *error_code = [NSString stringWithFormat:@"%@", response[@"error_code"]];
            if ([error_code isEqualToString:@"0"]) {
                
                [QMUITips showSucceed:@"发布成功"];
                
                [self finishFabu];
                
            }
            else{
                
                
                [QMUITips showError:response[@"error_msg"]];
                
            }
            
        } failure:^(NSError *error) {
            [QMUITips showError:[error localizedDescription]];
            
        }];
    }
    
    
    
}

//- (BOOL)shouldHideKeyboardWhenTouchInView:(UIView *)view {
//    return YES; // 表示点击空白区域都会降下键盘
//}

#pragma mark - <QMUITextFieldDelegate>

- (void)textField:(QMUITextField *)textField didPreventTextChangeInRange:(NSRange)range replacementString:(NSString *)replacementString {
    
    //    [QMUITips showWithText:[NSString stringWithFormat:@"文字不能超过 %@ 个字符", @(textField.maximumTextLength)] inView:self.view hideAfterDelay:2.0];
}




#pragma mark - <QMUITextViewDelegate>

// 实现这个 delegate 方法就可以实现自增高
- (void)textView:(QMUITextView *)textView newHeightAfterTextChanged:(CGFloat)height {
    height = fmax(height, self.textViewMinimumHeight);
    BOOL needsChangeHeight = CGRectGetHeight(textView.frame) != height;
    if (needsChangeHeight) {
        [self.view setNeedsLayout];
        [self.view layoutIfNeeded];
    }
}

- (void)textView:(QMUITextView *)textView didPreventTextChangeInRange:(NSRange)range replacementText:(NSString *)replacementText {
    
    //    [QMUITips showWithText:[NSString stringWithFormat:@"文字不能超过 %@ 个字符", @(textView.maximumTextLength)] inView:self.view hideAfterDelay:.8];
}

// 可以利用这个 delegate 来监听发送按钮的事件，当然，如果你习惯以前的方式的话，也可以继续在 textView:shouldChangeTextInRange:replacementText: 里处理
- (BOOL)textViewShouldReturn:(QMUITextView *)textView {
    //    [QMUITips showSucceed:[NSString stringWithFormat:@"成功发送文字：%@", textView.text] inView:self.view hideAfterDelay:1];
    //    textView.text = nil;
    
    // return YES 表示这次 return 按钮的点击是为了触发“发送”，而不是为了输入一个换行符
    return YES;
}
#pragma mark - LxGridViewDataSource

/// 以下三个方法为长按排序相关代码
- (BOOL)collectionView:(UICollectionView *)collectionView canMoveItemAtIndexPath:(NSIndexPath *)indexPath {
    return indexPath.item < self.lastSelectPhotos.count;
}

- (BOOL)collectionView:(UICollectionView *)collectionView itemAtIndexPath:(NSIndexPath *)sourceIndexPath canMoveToIndexPath:(NSIndexPath *)destinationIndexPath {
    return (sourceIndexPath.item < self.lastSelectPhotos.count && destinationIndexPath.item < self.lastSelectPhotos.count);
}

- (void)collectionView:(UICollectionView *)collectionView itemAtIndexPath:(NSIndexPath *)sourceIndexPath didMoveToIndexPath:(NSIndexPath *)destinationIndexPath {
    UIImage *image = self.lastSelectPhotos[sourceIndexPath.item];
    [self.lastSelectPhotos removeObjectAtIndex:sourceIndexPath.item];
    [self.lastSelectPhotos insertObject:image atIndex:destinationIndexPath.item];
    
    [_collectionView reloadData];
    
    
}

#pragma mark UICollectionView

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    
    if (self.lastSelectPhotos.count < self.maximumPhotos) {
        return self.lastSelectPhotos.count + 1;
    }
    return  self.maximumPhotos;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    TZTestCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"TZTestCell" forIndexPath:indexPath];
    cell.videoImageView.hidden = YES;
    if (indexPath.item == self.lastSelectPhotos.count) {
        cell.imageView.image = [UIImage imageNamed:@"AlbumAddBtn"];
        cell.deleteBtn.hidden = YES;
        cell.gifLable.hidden = YES;
    } else {
        cell.imageView.image = self.lastSelectPhotos[indexPath.item];
        //        cell.asset = _selectedAssets[indexPath.item];
        cell.deleteBtn.hidden = NO;
    }
    //    if (!self.allowPickingGifSwitch.isOn) {
    //        cell.gifLable.hidden = YES;
    //    }
    cell.deleteBtn.tag = indexPath.item;
    [cell.deleteBtn addTarget:self action:@selector(deleteBtnClik:) forControlEvents:UIControlEventTouchUpInside];
    return cell;
}
- (void)deleteBtnClik:(UIButton *)sender{
    if ([self collectionView:self.collectionView numberOfItemsInSection:0] <= self.lastSelectPhotos.count) {
        [self.lastSelectPhotos removeObjectAtIndex:sender.tag];
        [self.lastSelectAssets removeObjectAtIndex:sender.tag];
        [self.collectionView reloadData];
        return;
    }
    
    [self.lastSelectPhotos removeObjectAtIndex:sender.tag];
    [self.lastSelectAssets removeObjectAtIndex:sender.tag];
    [_collectionView performBatchUpdates:^{
        NSIndexPath *indexPath = [NSIndexPath indexPathForItem:sender.tag inSection:0];
        [self->_collectionView deleteItemsAtIndexPaths:@[indexPath]];
    } completion:^(BOOL finished) {
        [self->_collectionView reloadData];
    }];
    [self.collectionView reloadData];
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.item == self.lastSelectPhotos.count) {
        [self btnSelectPhotoLibrary];
        
        //        NSString *takePhotoTitle = @"拍照";
        
        //        UIAlertController *alertVc = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
        //        UIAlertAction *takePhotoAction = [UIAlertAction actionWithTitle:takePhotoTitle style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        //            [self showCamera];
        //        }];
        //        [takePhotoAction setValue:rgb(51,51,51) forKey:@"_titleTextColor"];
        //
        //        [alertVc addAction:takePhotoAction];
        //        UIAlertAction *imagePickerAction = [UIAlertAction actionWithTitle:@"去相册选择" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        //            [self btnSelectPhotoLibrary];
        //        }];
        //        [imagePickerAction setValue:rgb(51,51,51) forKey:@"_titleTextColor"];
        //
        //        [alertVc addAction:imagePickerAction];
        //        UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
        //        [cancelAction setValue:rgb(51,51,51) forKey:@"_titleTextColor"];
        //
        //        [alertVc addAction:cancelAction];
        //        UIPopoverPresentationController *popover = alertVc.popoverPresentationController;
        //        UICollectionViewCell *cell = [collectionView cellForItemAtIndexPath:indexPath];
        //        if (popover) {
        //            popover.sourceView = cell;
        //            popover.sourceRect = cell.bounds;
        //            popover.permittedArrowDirections = UIPopoverArrowDirectionAny;
        //        }
        //        [self presentViewController:alertVc animated:YES completion:nil];
    } else { // preview photos or video / 预览照片或者视频
        //        PHAsset *asset = _selectedAssets[indexPath.item];
        //        // preview photos / 预览照片
        //        TZImagePickerController *imagePickerVc = [[TZImagePickerController alloc] initWithSelectedAssets:nil selectedPhotos:self.lastSelectPhotos index:indexPath.item];
        //        imagePickerVc.maxImagesCount = 17;
        //        imagePickerVc.allowPickingGif = NO;
        //        imagePickerVc.allowPickingOriginalPhoto = NO;
        //        imagePickerVc.allowPickingMultipleVideo = NO;
        //        //        imagePickerVc.showSelectedIndex = YES;
        //        imagePickerVc.isSelectOriginalPhoto = _isSelectOriginalPhoto;
        //        [imagePickerVc setDidFinishPickingPhotosHandle:^(NSArray<UIImage *> *photos, NSArray *assets, BOOL isSelectOriginalPhoto) {
        //            [self->self.lastSelectPhotos addObjectsFromArray:photos];
        ////            self->_selectedAssets = [NSMutableArray arrayWithArray:assets];
        //            self->_isSelectOriginalPhoto = isSelectOriginalPhoto;
        //            [self->_collectionView reloadData];
        //            self->_collectionView.contentSize = CGSizeMake(0, ((self->self.lastSelectPhotos.count + 2) / 3 ) * (self->_margin + self->_itemWH));
        //        }];
        //        [self presentViewController:imagePickerVc animated:YES completion:nil];
        
//        NSMutableArray *browserDataArr = [NSMutableArray array];
//

    }
}
#pragma mark - ================== 相册选图、拍照、预览图片 ==================
- (void)btnSelectPhotoPreview
{
    [self showWithPreview:YES];
}

- (void)btnSelectPhotoLibrary
{
    [self showWithPreview:NO];
}

- (void)showWithPreview:(BOOL)preview
{
    ZLPhotoActionSheet *a = [self getPas];
    
    if (preview) {
        [a showPreviewAnimated:YES];
    } else {
        [a showPhotoLibrary];
    }
}

- (void)showCamera
{
    ZLCustomCamera *camera = [[ZLCustomCamera alloc] init];
    camera.allowRecordVideo = NO;
    @zl_weakify(self);
    camera.doneBlock = ^(UIImage *image, NSURL *videoUrl) {
        @zl_strongify(self);
        //        [self saveImage:image videoUrl:videoUrl];
        if (image) {
            
            //            [self upload_portrait_and_update:@[image]];
        }
    };
    
    [self showDetailViewController:camera sender:nil];
}


- (ZLPhotoActionSheet *)getPas
{
    ZLPhotoActionSheet *actionSheet = [[ZLPhotoActionSheet alloc] init];
    
#pragma mark - 参数配置 optional，可直接使用 defaultPhotoConfiguration
    
    //以下参数为自定义参数，均可不设置，有默认值
    //    actionSheet.configuration.sortAscending = self.sortSegment.selectedSegmentIndex==0;
    //    actionSheet.configuration.allowSelectImage = self.selImageSwitch.isOn;
    //    actionSheet.configuration.allowSelectGif = self.selGifSwitch.isOn;
    actionSheet.configuration.allowSelectVideo = NO;
    //    actionSheet.configuration.allowSelectLivePhoto = self.selLivePhotoSwitch.isOn;
    //    actionSheet.configuration.allowForceTouch = self.allowForceTouchSwitch.isOn;
    //    actionSheet.configuration.allowEditImage = self.allowEditSwitch.isOn;
    //    actionSheet.configuration.allowEditVideo = self.allowEditVideoSwitch.isOn;
    //    actionSheet.configuration.allowSlideSelect = self.allowSlideSelectSwitch.isOn;
    //    actionSheet.configuration.allowMixSelect = self.mixSelectSwitch.isOn;
    //    actionSheet.configuration.allowDragSelect = self.allowDragSelectSwitch.isOn;
    //设置相册内部显示拍照按钮
    //    actionSheet.configuration.allowTakePhotoInLibrary = self.takePhotoInLibrarySwitch.isOn;
    //    //设置在内部拍照按钮上实时显示相机俘获画面
    //    actionSheet.configuration.showCaptureImageOnTakePhotoBtn = self.showCaptureImageSwitch.isOn;
    //    //设置照片最大预览数
    //    actionSheet.configuration.maxPreviewCount = self.previewTextField.text.integerValue;
    //    //设置照片最大选择数
    actionSheet.configuration.maxSelectCount = self.maximumPhotos;
    //    actionSheet.configuration.maxVideoSelectCountInMix = 3;
    //    actionSheet.configuration.minVideoSelectCountInMix = 1;
    //设置允许选择的视频最大时长
    //    actionSheet.configuration.maxVideoDuration = self.maxVideoDurationTextField.text.integerValue;
    //    //设置照片cell弧度
    //    actionSheet.configuration.cellCornerRadio = self.cornerRadioTextField.text.floatValue;
    //单选模式是否显示选择按钮
    //    actionSheet.configuration.showSelectBtn = YES;
    //是否在选择图片后直接进入编辑界面
    //    actionSheet.configuration.editAfterSelectThumbnailImage = self.editAfterSelectImageSwitch.isOn;
    //是否保存编辑后的图片
    //    actionSheet.configuration.saveNewImageAfterEdit = NO;
    //设置编辑比例
    //    actionSheet.configuration.clipRatios = @[GetClipRatio(7, 1)];
    //是否在已选择照片上显示遮罩层
    //    actionSheet.configuration.showSelectedMask = self.maskSwitch.isOn;
    //    actionSheet.configuration.showSelectedIndex = NO;
    //颜色，状态栏样式
    //    actionSheet.configuration.previewTextColor = [UIColor brownColor];
    //    actionSheet.configuration.selectedMaskColor = [UIColor purpleColor];
    //    actionSheet.configuration.navBarColor = [UIColor orangeColor];
    //    actionSheet.configuration.navTitleColor = [UIColor blackColor];
    //    actionSheet.configuration.bottomBtnsNormalTitleColor = kRGB(80, 160, 100);
    //    actionSheet.configuration.bottomBtnsDisableBgColor = kRGB(190, 30, 90);
    //    actionSheet.configuration.bottomViewBgColor = [UIColor blackColor];
    //    actionSheet.configuration.statusBarStyle = UIStatusBarStyleDefault;
    //是否允许框架解析图片
    //    actionSheet.configuration.shouldAnialysisAsset = self.allowAnialysisAssetSwitch.isOn;
    //框架语言
    //    actionSheet.configuration.languageType = self.languageSegment.selectedSegmentIndex;
    //自定义多语言
    //    actionSheet.configuration.customLanguageKeyValue = @{@"ZLPhotoBrowserCameraText": @"没错，我就是一个相机"};
    //自定义图片
    //    actionSheet.configuration.customImageNames = @[@"zl_navBack"];
    
    //是否使用系统相机
    //    actionSheet.configuration.useSystemCamera = YES;
    //    actionSheet.configuration.sessionPreset = ZLCaptureSessionPreset1920x1080;
    //    actionSheet.configuration.exportVideoType = ZLExportVideoTypeMp4;
    actionSheet.configuration.allowRecordVideo = NO;
    //    actionSheet.configuration.maxRecordDuration = 5;
#pragma mark - required
    //如果调用的方法没有传sender，则该属性必须提前赋值
    actionSheet.sender = self;
    //记录上次选择的图片
    actionSheet.arrSelectedAssets =  self.lastSelectAssets;
    
    @zl_weakify(self);
    [actionSheet setSelectImageBlock:^(NSArray<UIImage *> * _Nonnull images, NSArray<PHAsset *> * _Nonnull assets, BOOL isOriginal) {
        @zl_strongify(self);
        self.arrDataSources = images;
        self.isOriginal = isOriginal;
        self.lastSelectAssets = assets.mutableCopy;
        self.lastSelectPhotos = images.mutableCopy;
        
        NSLog(@"image:%@", images);
        //解析图片
        [self anialysisAssets:assets original:isOriginal];
        
    }];
    
    actionSheet.selectImageRequestErrorBlock = ^(NSArray<PHAsset *> * _Nonnull errorAssets, NSArray<NSNumber *> * _Nonnull errorIndex) {
        NSLog(@"图片解析出错的索引为: %@, 对应assets为: %@", errorIndex, errorAssets);
    };
    
    actionSheet.cancleBlock = ^{
        NSLog(@"取消选择图片");
    };
    
    return actionSheet;
}

- (void)anialysisAssets:(NSArray<PHAsset *> *)assets original:(BOOL)original
{
    ZLProgressHUD *hud = [[ZLProgressHUD alloc] init];
    //该hud自动15s消失，请使用自己项目中的hud控件
    [hud show];
    
    
    @zl_weakify(self);
    [ZLPhotoManager anialysisAssets:assets original:original completion:^(NSArray<UIImage *> *images) {
        @zl_strongify(self);
        [hud hide];
        self.arrDataSources = images;
        self.lastSelectPhotos = images.mutableCopy;
        
        NSLog(@"%@", images);
        [self.collectionView reloadData];
        
    }];
}

@end
